/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Component = require("editgrid");
	var aw = require("ajaxwrapper");
	var fetchProperties = require("../constant/fetchProperties")
	var tem=[];
	
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-editgrid",	
            	autoRender:false,
				model : {
				 columns  : [{
					 name : "productType.name",
					 label : "产品类型",
				 },{
					 name : "productBatch.name",
					 label : "产品批次",
				 },{
					 name : "price",
					 label : "产品价格（元）",
				 },{
					 name : "validity",
					 label : "有效期（年）",
				 },{
					 name : "liveDays",
					 label : "居住期限（天/间）",
				 },{
					 name : "",
					 label : "费用抵扣规则",
				 },{
					 name : "expenseScope",
					 label : "费用抵扣适用范围",
					 format:function(value,row){
						 var expenseScope=row.expenseScope
						 var str ="";
						 if(expenseScope&&expenseScope.length>0){
							 for(var i=0;i<expenseScope.length;i++){
								 if(i<expenseScope.length-1){
									 str+=expenseScope[i].name+","
								 }else{
									 str+=expenseScope[i].name
								 }
							 }
						 }
						 return str;
					 }
				 },{
					 name : "discount",
					 label : "床位费折扣",
				 },{
					 name : "bedScope",
					 label : "床位费折扣适用范围",
					 format:function(value,row){
						 var bedScope=row.bedScope
						 var str ="";
						 if(bedScope&&bedScope.length>0){
							 for(var i=0;i<bedScope.length;i++){
								 if(i<bedScope.length-1){
									 str+=bedScope[i].name+","
								 }else{
									 str+=bedScope[i].name
								 }
							 }
						 }
						 return str;
					 }
				 },{
					 name : "",
					 label : "返现规则",
				 },{
					 name : "rebatesScope",
					 label : "返现适用范围",
					 format:function(value,row){
						 var rebatesScope=row.rebatesScope
						 var str ="";
						 if(rebatesScope&&rebatesScope.length>0){
							 for(var i=0;i<rebatesScope.length;i++){
								 if(i<rebatesScope.length-1){
									 str+=rebatesScope[i].name+","
								 }else{
									 str+=rebatesScope[i].name
								 }
							 }
						 }
						 return str;
					 }
				 },{
					 name : "",
					 label : "补贴规则",
				 },{
					 name : "subsidyScope",
					 label : "补贴适用范围",
					 format:function(value,row){
						 var subsidyScope=row.subsidyScope
						 var str ="";
						 if(subsidyScope&&subsidyScope.length>0){
							 for(var i=0;i<subsidyScope.length;i++){
								 if(i<subsidyScope.length-1){
									 str+=subsidyScope[i].name+","
								 }else{
									 str+=subsidyScope[i].name
								 }
							 }
						 }
						 return str;
					 }
				 },{
					 name : "operate",
					 label : "操作",
					 format:"button",
						formatparams:[{
							id:"edit",
							text:"修改",
							handler:function(index,data,rowEle){
								 widget.set("index",index);
								 widget.set("type",true);
								 widget.show(".J-editform").hide([".J-form",".J-grid",".J-editgrid"]);
			        	         $(".J-button").addClass("hidden");
			        	         widget.get("subnav").hide(["cancel","save"]);
								 widget.get("editform").setData(data);
							}
						},{
							key:"delete",
							text:"删除",
							handler:function(index,data,rowEle){
								if(data.pkProductDetail!=""){
									tem.push(data.pkProductDetail);
									widget.set("tem",tem);
								}
								widget.get("editgrid").remove(index, rowEle);
							}
						}]
				 }]
				}
            });
            widget.set("editgrid", component);
        }
    };
    module.exports = instance;
});
